var nursingCostArray = null;

$(function() {
	load_nursingCost_select();
	load_nursingCost_cond_select();
});

function load_nursingCost_select() {
	if($('#nursingCost_select').length==0) {return;}

	$('#nursingCost_select').html('<option value="" selected></option>');

	findAll_basic(path+'/nursingCost/findAll', function(response) {
		for(var i=0; i<response.data.length; i++) {
			$('#nursingCost_select').append('<option nursingCostName="' + response.data[i].nursingCostName
				+ '" nursingCostPrice="' + response.data[i].price + '" value="' + response.data[i].nursingCostId
				+ '">' + response.data[i].nursingCostName + ' 每月' + response.data[i].price + '元 半个月'
				+ (response.data[i].price/2.0).toFixed(2) + '元'
				+ '</option>');
		}
		
		nursingCostArray = response.data;
		
		_addChangeListener("#nursingCost_select", function() {
			var option = $('#nursingCost_select option:selected');
			var nursingCostId_select = $('#nursingCost_select').val();
			
			if(view && view.data) {
				view.data.nursingCostName = option.text();
			}
			
			for(var i=0; i<nursingCostArray.length; i++) {
				if(nursingCostArray[i].nursingCostId==nursingCostId_select) {
					if(view && view.data) {
						view.data.nursingCostId = nursingCostArray[i].nursingCostId;
						view.data.nursingCostPrice = nursingCostArray[i].price;
					}
				}
			}
		});
	});
}

function load_nursingCost_cond_select() {
	if($('#nursingCost_cond_select').length==0) {return;}

	$('#nursingCost_cond_select').html('<option value="" selected></option>');

	findAll_basic(path+'/nursingCost/findAll', function(response) {
		for(var i=0; i<response.data.length; i++) {
			$('#nursingCost_cond_select').append('<option value="' + response.data[i].nursingCostId
				+ '">' + response.data[i].nursingCostName + ' ' + response.data[i].price + '元/月 '
				+ (response.data[i].price/2.0).toFixed(2) + '元/半个月'
				+ '</option>');
		}
	});
}
